package com.lmscn.lms.api.model;

import com.jfinal.plugin.activerecord.Model;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Czl on 2015/10/23.
 */
@SuppressWarnings("serial")
public class CourseTopic extends Model<CourseTopic> {
	
	public static final CourseTopic dao = new CourseTopic();
	
    public List<CourseTopic> getCourseTopicList(long studyPlanId) {
        return dao.find("select t.id, t.topic_name, t.course_ids, t.required_period,"
        		+ " t.required_num, t.seq from t_course_topic t"
        		+ " where t.study_plan_id = ? order by t.seq;", studyPlanId);
    }
    
    public CourseTopic getCourseTopicById(long id){
        return dao.findFirst("select * from t_course_topic where id = ?;", id);
    }
    
    
	public String getExcludeCourseIds(String studyPlanIds) {
		StringBuffer idBuf = null;
		if (studyPlanIds==null) {
			return null;
		}
		String hql = "select * from t_course_topic"
				+ " where study_plan_id in ("+ studyPlanIds +") order by id desc";
		
		List<CourseTopic> list = dao.find(hql);
		if (list!=null && list.size()>0) {
			idBuf = new StringBuffer();
			for (CourseTopic courseTopic : list) {
				String courseIds = courseTopic.getStr("course_ids");
				idBuf.append(courseIds).append(",");
			}
		}
		
		return idBuf!=null ? idBuf.substring(0, idBuf.length()-1) : null;
	}

}

